<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>    
        function find(n, m) {
            var arr = [];
            for (var i = 1; i < n + 1; i++) {
                arr.push(i);
            }
            console.log(arr);
            while (arr.length > 1) {
                for (var i = 0; i < m - 1; i++) {
                    arr.push(arr.shift())
                    console.log(arr);
                }
                arr.shift();
            }
            return arr;
        }

        var re = find(20, 4);
        console.log(re);
    </script>
</body>

</html>